package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.common.minio.service.FileOpsService;
import com.atguigu.tingshu.common.result.Result;
import io.minio.MinioClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {

    @Autowired
    private FileOpsService fileOpsService;

    //Request URL: http://localhost:8500/api/album/fileUpload
    /**
     * 我们调用上传文件的接口，最后要求返回一个图像的url，用于前端回显
     * @return
     */
    @PostMapping("/fileUpload")
    @Operation(summary = "Minio文件系统交互接口")
    public Result uploadFile(@RequestPart("file") MultipartFile file){
        String picUrl = fileOpsService.uploadFile(file);
        return Result.ok(picUrl);
    }

}
